package com.dhl.cloud.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dhl.cloud.common.http.HttpResult;
import com.dhl.cloud.common.http.HttpUser;
import com.dhl.cloud.core.service.UserService;

/**
 *  封装用户退出的接口
 *
 */
@RestController
@RequestMapping(value = "/user")
public class LogOutController extends BaseController{

	@Autowired
	private UserService userService;
	
	/**
	 * 登出接口
	 * @return 返回成功失败
	 */
	@PostMapping(value = "/logout")
	public HttpResult logout(HttpServletRequest request) {
		//删除用户token
		HttpUser user = getUser(request);

		userService.updateUserOnlineFlag(user.getUsername(), 0);
		/*HttpSession session = request.getSession(false);
		if (session != null) {
			session.removeAttribute(user.getUsername());
			session.invalidate();
		}*/

		return HttpResult.success("");
	}


}
